package personal.vivian.builder;

import personal.vivian.interf.Option;
import personal.vivian.logic.TemplatItem;

import java.util.ArrayList;
import java.util.List;

public class ItemBuilder<T,C> {
    private List<Option> options=new ArrayList<>();
    private TransformBuilder transformBuilder;
    private String name;
    private String fieldName;
    private T modelProxy;
    private TemplatItem item;
    public ItemBuilder(Option ... option){
        option(option);
    }

    public ItemBuilder(TransformBuilder transformBuilder, String name, String fieldName, T modelProxy,Option... options) {
        option(options);
        this.transformBuilder = transformBuilder;
        this.name = name;
        this.fieldName = fieldName;
        this.modelProxy = modelProxy;
    }
    public ItemBuilder(TransformBuilder transformBuilder, String name,TemplatItem item, String fieldName, T modelProxy,Option... options) {
        this.transformBuilder = transformBuilder;
        this.name = name;
        this.fieldName = fieldName;
        this.modelProxy = modelProxy;
        this.item=item;
        option(options);
    }

    public void buildItem(){
        for(Option option:options){
            option.apply(this);
        }
        options.clear();
    }
    public List<Option> getOptions() {
        return options;
    }

    public void setOptions(List<Option> options) {
        this.options = options;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getFieldName() {
        return fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public TransformBuilder getTransformBuilder() {
        return transformBuilder;
    }

    public void setTransformBuilder(TransformBuilder transformBuilder) {
        this.transformBuilder = transformBuilder;
    }

    public void option(Option ... option) {
        for(Option o:option){
            this.options.add(o);
        }
    }
    public TemplatItem getItem(){
        if(item!=null){
            return item;
        }
        TemplatItem item = getTransformBuilder().getItem(name, fieldName, true);
        return item;
    }
}
